package com.ruoyi.system.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.QtRecommend;
import com.ruoyi.system.service.IQtRecommendService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 推荐Controller
 * 
 * @author ZQQ
 * @date 2021-11-27
 */
@RestController
@RequestMapping("/system/recommend")
public class QtRecommendController extends BaseController
{
    @Autowired
    private IQtRecommendService qtRecommendService;

    /**
     * 查询推荐列表
     */
    @PreAuthorize("@ss.hasPermi('system:recommend:list')")
    @GetMapping("/list")
    public TableDataInfo list(QtRecommend qtRecommend)
    {
        startPage();
        List<QtRecommend> list = qtRecommendService.selectQtRecommendList(qtRecommend);
        return getDataTable(list);
    }

    /**
     * 导出推荐列表
     */
    @PreAuthorize("@ss.hasPermi('system:recommend:export')")
    @Log(title = "推荐", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(QtRecommend qtRecommend)
    {
        List<QtRecommend> list = qtRecommendService.selectQtRecommendList(qtRecommend);
        ExcelUtil<QtRecommend> util = new ExcelUtil<QtRecommend>(QtRecommend.class);
        return util.exportExcel(list, "推荐数据");
    }

    /**
     * 获取推荐详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:recommend:query')")
    @GetMapping(value = "/{recomId}")
    public AjaxResult getInfo(@PathVariable("recomId") String recomId)
    {
        return AjaxResult.success(qtRecommendService.selectQtRecommendByRecomId(recomId));
    }

    /**
     * 新增推荐
     */
    @PreAuthorize("@ss.hasPermi('system:recommend:add')")
    @Log(title = "推荐", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QtRecommend qtRecommend)
    {
        return toAjax(qtRecommendService.insertQtRecommend(qtRecommend));
    }

    /**
     * 修改推荐
     */
    @PreAuthorize("@ss.hasPermi('system:recommend:edit')")
    @Log(title = "推荐", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QtRecommend qtRecommend)
    {
        return toAjax(qtRecommendService.updateQtRecommend(qtRecommend));
    }

    /**
     * 删除推荐
     */
    @PreAuthorize("@ss.hasPermi('system:recommend:remove')")
    @Log(title = "推荐", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recomIds}")
    public AjaxResult remove(@PathVariable String[] recomIds)
    {
        return toAjax(qtRecommendService.deleteQtRecommendByRecomIds(recomIds));
    }
}
